//
//  AppDelegateExtension.swift
//  zhende
//
//  Created by 陆文宇 on 2017/5/26.
//  Copyright © 2017年 chenliang. All rights reserved.
//

import UIKit

extension AppDelegate {
    
    func configThird() {
        System.configBMKMap(appKey: "h8N2wG3YnfqhGaH0mAPzGRpVrDvaxQAV")
        System.configGeTui(appId: "ZM9KSmMM6O8LjFLKFXySv1", appKey: "86cf6GQ9U08o2XnBoOUCSA", appSecret: "mW6a3J8u6C8ONljxzXh4a8")
    }
    
    
    // MARK: - Config

    
    // MARK: - Delegate
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let deviceToken_ns = NSData(data: deviceToken)
        var token = deviceToken_ns.description.trimmingCharacters(in: CharacterSet(charactersIn: "<>"));
        token = token.replacingOccurrences(of: " ", with: "")
        
        GeTuiSdk.registerDeviceToken(token)
        yy_Log("DeviceToken Success: \(token)")
    }
    
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        yy_Log("DeviceToken Error: " + error.localizedDescription);
        yy_LogError(error.localizedDescription)
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
        application.applicationIconBadgeNumber = 0;
        yy_Log("Receive RemoteNotification: \(userInfo)")
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        GeTuiSdk.handleRemoteNotification(userInfo)
        
        yy_Log("Receive RemoteNotification: \(userInfo)")
        completionHandler(.newData)
    }
    
    func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
        if !UMSocialManager.default().handleOpen(url) {
            
        }
        return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        if !UMSocialManager.default().handleOpen(url, options: options) {
            
        }
        return true
    }


}
